import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, AlertController} from 'ionic-angular';

import { Https } from '../../app/http.service'
/**
 * Generated class for the BalanceinfoPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
	selector: 'page-balanceinfo',
	templateUrl: 'balanceinfo.html',
})
export class BalanceinfoPage {
	balanceInfoUrl = new Https().Url + "act=goods&op=app_bill_info"
	data: Array<{ 'lg_id': string, 'lg_av_amount': string, 'lg_add_time': string,'lg_desc':string}>
	statu:number
	constructor(public navCtrl: NavController, public navParams: NavParams, public alertCtrl: AlertController) {
	}

	ionViewDidLoad() {
		let then = this
		fetch(this.balanceInfoUrl, {
			method: "post",
			headers: {
				'Content-Type': 'application/x-www-form-urlencoded'
			},
			body: "mid=" + localStorage.getItem("mid") + "&token=" + localStorage.getItem("token") + "&page=0,20",
		}).then((response) => {
			response.text().then((con) => {
				let resource = JSON.parse(con);
				if (resource.code == null  || resource != "" ){
					this.data = resource;
					console.log(this.data);
				}else{
					this.statu = 0
				}
					
				
			})
		}).catch((err) => {
			let confirm = then.alertCtrl.create({
				title: '温馨提示',
				message: err,
				buttons: [
					{ text: '确定' },

				]
			});
			confirm.present();
		})
	}

	doInfinite(infiniteScroll) {
		let then = this
		fetch(this.balanceInfoUrl, {
			method: "post",
			headers: {
				'Content-Type': 'application/x-www-form-urlencoded'
			},
			body: "mid=" + localStorage.getItem("mid") + "&token=" + localStorage.getItem("token") + "&page=" + this.data.length + "," + (this.data.length+20),
		}).then((response) => {
			response.text().then((con) => {
				let resource = JSON.parse(con);
				for (let i of resource){
					this.data.push(i);
				}
				infiniteScroll.complete();
			})
		}).catch((err) => {
			let confirm = then.alertCtrl.create({
				title: '温馨提示',
				message: err,
				buttons: [
					{ text: '确定' },

				]
			});
			confirm.present();
		})
	}

}
